package com.java.simple.smallspring.aop.framework;

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Method;
import lombok.RequiredArgsConstructor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @author zhoujunlin
 * @date 2022年09月10日 16:34
 * @desc <p>Invokes the target object using reflection. Subclasses can override the
 * #invokeJoinpoint() method to change this behavior, so this is also
 * a useful base class for more specialized MethodInvocation implementations.
 */
@RequiredArgsConstructor
public class ReflectiveMethodInvocation implements MethodInvocation {
    /**
     * 目标对象
     */
    protected final Object target;
    /**
     * 方法
     */
    protected final Method method;
    /**
     * 入参
     */
    protected final Object[] arguments;


    @Override
    public Method getMethod() {
        return method;
    }

    @Override
    public Object[] getArguments() {
        return arguments;
    }

    @Override
    public Object proceed() throws Throwable {
        return method.invoke(target, arguments);
    }

    @Override
    public Object getThis() {
        return target;
    }

    @Override
    public AccessibleObject getStaticPart() {
        return method;
    }
}
